package org.gem.example.sale;

import org.gem.example.product.Fruit;
import org.gem.example.strategy.DiscountStrategy;

import java.math.BigDecimal;

public class ShoppingItem {
    private final Fruit fruit;
    private final double quantity;
    private DiscountStrategy discountStrategy;

    public ShoppingItem(Fruit fruit, double quantity) {
        this.fruit = fruit;
        this.quantity = quantity;
    }

    public ShoppingItem(Fruit fruit, double quantity, DiscountStrategy discountStrategy) {
        this(fruit, quantity);
        this.discountStrategy = discountStrategy;
    }

    public BigDecimal getTotalPrice() {
        BigDecimal originalPrice = fruit.calculateCost(quantity);
        return discountStrategy != null ? discountStrategy.applyDiscount(originalPrice) : originalPrice;
    }

    public Fruit getFruit() {
        return fruit;
    }

    public double getQuantity() {
        return quantity;
    }

}
